/* /////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2004-2007 Intel Corporation. All Rights Reserved.
//
//
//          VC-1 (VC1) decoder, MV Differential tables
//
*/
#include "umc_defs.h"

#if defined (UMC_ENABLE_VC1_VIDEO_DECODER) || defined (UMC_ENABLE_VC1_SPLITTER) || defined (UMC_ENABLE_VC1_VIDEO_ENCODER)

#include "umc_vc1_common_defs.h"
#include "umc_vc1_common_mvdiff_tbl.h"

//Checked
//VC-1 Table 247: Motion Vector Differential VLC Table 0
//Index VLC     VLC  Index   VLC      VLC  Index VLC      VLC
//     Codeword Size         Codeword Size       Codeword Size
//0        0     6     25     167      10    50       21    5
//1        2     7     26     49        8    51       22    5
//2        3     7     27     194      10    52       39    6
//3        8     8     28     195      10    53       204   9
//4        576   14    29     581      14    54       103   8
//5        3     6     30     582      14    55       23    5
//6        2     5     31     583      14    56       24    5
//7        6     6     32     292      13    57       25    5
//8        5     7     33     293      13    58       104   7
//9        577   14    34     294      13    59       410   10
//10       578   14    35     13        6    60       105   7
//11       7     6     36     2         3    61       106   7
//12       8     6     37     7         5    62       107   7
//13       9     6     38     24        6    63       108   7
//14       40    8     39     50        8    64       109   7
//15       19    9     40     102       9    65       220   8
//16       37    10    41     295      13    66       411   10
//17       82    9     42     13        5    67       442   9
//18       21    7     43     7         4    68       222   8
//19       22    7     44     8         4    69       443   9
//20       23    7     45     18        5    70       446   9
//21       579   14    46     50        7    71       447   9
//22       580   14    47     103       9    72       7     3
//23       166   10    48     38        6
//24       96    9     49     20        5

const extern Ipp32s VC1_Progressive_MV_Diff_tbl0[] =
{
 14, /* max bits */
 2,  /* total subtables */
 8, 6 ,/* subtable sizes */

 0, /* 1-bit codes */
 0, /* 2-bit codes */
 2, /* 3-bit codes */
    7,  0x116024,      //72,   //INTRA
    2,  0x106125,      //36,
 2, /* 4-bit codes */
    7,  0x101107,     //43,
    8,  0x101208,     //44,
 10, /* 5-bit codes */
    2,  0x001107,     //6,
    7,  0x100101,     //37,
    13, 0x101006,     //42,
    20, 0x10210D,     //49,
    21, 0x10220E,     //50,
    22, 0x10230F,     //51,
    23, 0x103113,     //55,
    24, 0x103214,     //56,
    25, 0x103315,     //57,
    18, 0x101309,     //45,

 10, /* 6-bit codes */
    0,  0x000101,     //0,
    3,  0x001006,     //5,
    6,  0x001208,     //7,
    7,  0x00200C,     //11,
    8,  0x00210D,     //12,
    9,  0x00220E,     //13,
    13, 0x016024,     //35,  //INTRA
    24, 0x100202,     //38,
    38, 0x10200C,     //48,
    39, 0x102410,     //52,

 13,/* 7-bit codes */
    2,   0x000202,      //1,
    3,   0x000303,      //2,
    5,   0x001309,      //8,
    21,  0x003113,      //18,
    22,  0x003214,      //19,
    23,  0x003315,      //20,
    50,  0x10140A,      //46,
    104, 0x103416,      //58,
    105, 0x104018,      //60,
    106, 0x104119,      //61,
    107, 0x10421A,      //62,
    108, 0x10431B,      //63,
    109, 0x10441C,      //64,

 7, /* 8-bit codes */
    8,   0x000404,      //3,
    40,  0x00230F,      //14,
    49,  0x00431B,      //26,
    50,  0x100303,      //39,
    103, 0x103012,      //54,
    220, 0x10451D,      //65,
    222, 0x105220,      //68,

 10,/* 9-bit codes */
    19,  0x002410,     //15,
    82,  0x003012,     //17,
    96,  0x004119,     //24,
    102, 0x100404,     //40,
    103, 0x10150B,     //47,
    204, 0x102511,     //53,
    442, 0x10511F,     //67,
    443, 0x105321,     //69,
    446, 0x105422,     //70,
    447, 0x105523,     //71,

 7, /* 10-bit codes */
    37,  0x002511,     //16,
    166, 0x004018,    //23,
    167, 0x00421A,    //25,
    194, 0x00441C,    //27,
    195, 0x00451D,    //28,
    410, 0x103517,    //59,
    411, 0x10501E,    //66,

 0, /* 11-bit codes */

 0, /* 12-bit codes */

 4, /* 13-bit codes */
    292, 0x005321,    //32,
    293, 0x005422,    //33,
    294, 0x005523,    //34,
    295, 0x100505,    //41,

 8, /* 14-bit codes */
    576, 0x000505,    //4,
    577, 0x00140A,    //9,
    578, 0x00150B,    //10,
    579, 0x003416,    //21,
    580, 0x003517,    //22,
    581, 0x00501E,    //29,
    582, 0x00511F,    //30,
    583, 0x005220,    //31,

-1 /* end of table */
};
//Checked
//VC-1 Table 248: Motion Vector Differential VLC Table 1
//Index   VLC      VLC   Index  VLC         VLC   Index  VLC         VLC
//       Codeword  Size         Codeword    Size         Codeword    Size
//0          0      5     25      3012       14     50     58          6
//1          4      7     26      3013       14     51     163         8
//2          5      7     27      3014       14     52     236         8
//3          3      6     28      3015       14     53     237         8
//4          4      6     29      3016       14     54     3023        14
//5          3      5     30      3017       14     55     119         7
//6          4      5     31      3018       14     56     120         7
//7          5      6     32      3019       14     57     242         8
//8          20     7     33      3020       14     58     122         7
//9          6      5     34      3021       14     59     486         9
//10         21     7     35      3022       14     60     1512        13
//11         44     8     36      1           2     61     487         9
//12         45     8     37      4           3     62     246         8
//13         46     8     38      15          6     63     494         9
//14         3008   14    39      160         8     64     1513        13
//15         95     9     40      161         8     65     495         9
//16         112    9     41      41          6     66     1514        13
//17         113    9     42      6           3     67     1515        13
//18         57     8     43      11          4     68     1516        13
//19         3009   14    44      42          6     69     1517        13
//20         3010   14    45      162         8     70     1518        13
//21         116    9     46      43          6     71     1519        13
//22         117    9     47      119         9     72     31          5
//23         3011   14    48      56          6
//24         118    9     49      57          6

const extern Ipp32s VC1_Progressive_MV_Diff_tbl1[] =
{
 14, /* max bits */
 2,  /* total subtables */
 8, 6 ,/* subtable sizes */

 0, /* 1-bit codes */
 1, /* 2-bit codes */
    1, 0x106125,      //36,
 2, /* 3-bit codes */
    4, 0x100101,      //37,
    6, 0x101006,      //42,
 1, /* 4-bit codes */
    11, 0x101107,     //43,
 5, /* 5-bit codes */
    0,  0x000101,      //0,
    31, 0x116024,      //72,    //INTRA
    6,  0x00140A,      //9,
    3,  0x001006,      //5,
    4,  0x001107,      //6,

 10, /* 6-bit codes */
    3,  0x000404,    //3,
    4,  0x000505,    //4,
    5,  0x001208,    //7,
    15, 0x100202,    //38,
    41, 0x100505,    //41,
    42, 0x101208,    //44,
    43, 0x10140A,    //46,
    56, 0x10200C,    //48,
    57, 0x10210D,    //49,
    58, 0x10220E,    //50,

 7,/* 7-bit codes */
    20,  0x001309,    //8,
    4,   0x000202,    //1,
    5,   0x000303,    //2,
    21,  0x00150B,    //10,
    119, 0x103113,    //55,
    120, 0x103214,    //56,
    122, 0x103416,    //58,

 12, /* 8-bit codes */
    44,  0x00200C,    //11,
    45,  0x00210D,    //12,
    46,  0x00220E,    //13,
    57,  0x003113,    //18,
    160, 0x100303,    //39,
    161, 0x100404,    //40,
    162, 0x101309,    //45,
    163, 0x10230F,    //51,
    236, 0x102410,    //52,
    237, 0x102511,    //53,
    242, 0x103315,    //57,
    246, 0x10421A,    //62,

 11,/* 9-bit codes */
    95,  0x002410,    //15,
    112, 0x002511,    //16,
    113, 0x003012,    //17,
    116, 0x003416,    //21,
    117, 0x003517,    //22,
    118, 0x004119,    //24,
    119, 0x10150B,    //47,
    486, 0x103517,    //59,
    487, 0x104119,    //61,
    494, 0x10431B,    //63,
    495, 0x10451D,    //65,

 0, /* 10-bit codes */

 0, /* 11-bit codes */

 0, /* 12-bit codes */

 8, /* 13-bit codes */
    1512, 0x104018,    //60,
    1513, 0x10441C,    //64,
    1514, 0x10501E,    //66,
    1515, 0x10511F,    //67,
    1516, 0x105220,    //68,
    1517, 0x105321,    //69,
    1518, 0x105422,    //70,
    1519, 0x105523,    //71,

 16, /* 14-bit codes */
    3008, 0x00230F,    //14,
    3009, 0x003214,    //19,
    3010, 0x003315,    //20,
    3011, 0x004018,    //23,
    3012, 0x00421A,    //25,
    3013, 0x00431B,    //26,
    3014, 0x00441C,    //27,
    3015, 0x00451D,    //28,
    3016, 0x00501E,    //29,
    3017, 0x00511F,    //30,
    3018, 0x005220,    //31,
    3019, 0x005321,    //32,
    3020, 0x005422,    //33,
    3021, 0x005523,    //34,
    3022, 0x016024,    //35,   //INTRA
    3023, 0x103012,    //54,

-1 /* end of table */
};

//Checked
//VC-1 Table 249: Motion Vector Differential VLC Table 2
//Index   VLC    VLC  Index   VLC    VLC  Index    VLC        VLC
//      Codeword Size       Codeword Size         Codeword    Size
//0         0      3   25     276     11    50      297        11
//1       512     12   26     277     11    51      298        11
//2       513     12   27     278     11    52      299        11
//3       514     12   28     279     11    53      300        11
//4       515     12   29     280     11    54      301        11
//5         2      3   30     281     11    55      302        11
//6         3      4   31     282     11    56      303        11
//7       258     11   32     283     11    57      304        11
//8       259     11   33     284     11    58      305        11
//9       260     11   34     285     11    59      306        11
//10      261     11   35     286     11    60      307        11
//11      262     11   36     1        1    61      308        11
//12      263     11   37     5        5    62      309        11
//13      264     11   38     287     11    63      310        11
//14      265     11   39     288     11    64      311        11
//15      266     11   40     289     11    65      312        11
//16      267     11   41     290     11    66      313        11
//17      268     11   42     6        4    67      314        11
//18      269     11   43     7        4    68      315        11
//19      270     11   44     291     11    69      316        11
//20      271     11   45     292     11    70      317        11
//21      272     11   46     293     11    71      318        11
//22      273     11   47     294     11    72      319        11
//23      274     11   48     295     11
//24      275     11   49     296     11

const extern Ipp32s VC1_Progressive_MV_Diff_tbl2[] =
{
 12, /* max bits */
 2,  /* total subtables */
 5, 7 ,/* subtable sizes */

 1, /* 1-bit codes */
    1, 0x101625,    //36,
 0, /* 2-bit codes */
 2, /* 3-bit codes */
    0, 0x000101,    //0,
    2, 0x001006,    //5,
 3, /* 4-bit codes */
    3, 0x001107,    //6,
    6, 0x101006,    //42,
    7, 0x101107,    //43,
 1, /* 5-bit codes */
    5, 0x100101,    //37,

 0, /* 6-bit codes */
 0,/* 7-bit codes */
 0, /* 8-bit codes */
 0,/* 9-bit codes */
 0, /* 10-bit codes */

 62, /* 11-bit codes */
    258, 0x001208,    //7,
    259, 0x001309,    //8,
    260, 0x00140A,    //9,
    261, 0x00150B,    //10,
    262, 0x00200C,    //11,
    263, 0x00210D,    //12,
    264, 0x00220E,    //13,
    265, 0x00230F,    //14,
    266, 0x002410,    //15,
    267, 0x002511,    //16,
    268, 0x003012,    //17,
    269, 0x003113,    //18,
    270, 0x003214,    //19,
    271, 0x003315,    //20,
    272, 0x003416,    //21,
    273, 0x003517,    //22,
    274, 0x004018,    //23,
    275, 0x004119,    //24,
    276, 0x00421A,    //25,
    277, 0x00431B,    //26,
    278, 0x00441C,    //27,
    279, 0x00451D,    //28,
    280, 0x00501E,    //29,
    281, 0x00511F,    //30,
    282, 0x005220,    //31,
    283, 0x005321,    //32,
    284, 0x005422,    //33,
    285, 0x005523,    //34,
    286, 0x016024,    //35,   //INTRA
    287, 0x100202,    //38,
    288, 0x100303,    //39,
    289, 0x100404,    //40,
    290, 0x100505,    //41,
    291, 0x101208,    //44,
    292, 0x101309,    //45,
    293, 0x10140A,    //46,
    294, 0x10150B,    //47,
    295, 0x10200C,    //48,
    296, 0x10210D,    //49,
    297, 0x10220E,    //50,
    298, 0x10230F,    //51,
    299, 0x102410,    //52,
    300, 0x102511,    //53,
    301, 0x103012,    //54,
    302, 0x103113,    //55,
    303, 0x103214,    //56,
    304, 0x103315,    //57,
    305, 0x103416,    //58,
    306, 0x103517,    //59,
    307, 0x104018,    //60,
    308, 0x104119,    //61,
    309, 0x10421A,    //62,
    310, 0x10431B,    //63,
    311, 0x10441C,    //64,
    312, 0x10451D,    //65,
    313, 0x10501E,    //66,
    314, 0x10511F,    //67,
    315, 0x105220,    //68,
    316, 0x105321,    //69,
    317, 0x105422,    //70,
    318, 0x105523,    //71,
    319, 0x116024,    //72,     //INTRA
 4, /* 12-bit codes */
    512, 0x000202,    //1,
    513, 0x000303,    //2,
    514, 0x000404,    //3,
    515, 0x000505,    //4,

-1 /* end of table */
};

//Checked
//VC-1 Table 250: Motion Vector Differential VLC Table 3
//Index   VLC     VLC     Index     VLC       VLC    Index    VLC      VLC
//      Codeword Size             Codeword    Size           Codeword  Size
//0         0     15       25        6         10      50       5       3
//1         1     11       26        14        11      51       18      5
//2         1     15       27        8         10      52       29      6
//3         2     15       28        106       15      53       152     8
//4         3     15       29        107       15      54       77      7
//5         4     15       30        108       15      55       24      5
//6         1     12       31        15        11      56       25      5
//7         5     15       32        109       15      57       26      5
//8         4     12       33        9         10      58       39      6
//9         3     11       34        55        14      59       108     7
//10        5     12       35        10        10      60       13      9
//11        8     12       36        1          4      61       109     7
//12        6     15       37        2          4      62       55      6
//13        9     12       38        1          5      63       56      6
//14        10    12       39        2          7      64       57      6
//15        11    12       40        3          8      65       116     7
//16        12    12       41        12         9      66       11      10
//17        7     15       42        6          5      67       153     8
//18        104   15       43        2          3      68       234     8
//19        14    12       44        6          4      69       235     8
//20        105   15       45        7          5      70       118     7
//21        4     10       46        28         6      71       119     7
//22        10    11       47        7          8      72       15      4
//23        15    12       48        15         5
//24        11    11       49        8          4

const extern Ipp32s VC1_Progressive_MV_Diff_tbl3[] =
{
 15, /* max bits */
 2,  /* total subtables */
 8, 7 ,/* subtable sizes */

 0, /* 1-bit codes */
 0, /* 2-bit codes */
 2, /* 3-bit codes */
    2, 0x101107,    //43,
    5, 0x10220E,    //50,
 5, /* 4-bit codes */
    1,  0x106125,    //36,
    2,  0x100101,    //37,
    6,  0x101208,    //44,
    8,  0x10210D,    //49,
    15, 0x116024,    //72,      //INTRA
 8, /* 5-bit codes */
    6,  0x101006,    //42,
    7,  0x101309,    //45,
    1,  0x100202,    //38,
    15, 0x10200C,    //48,
    18, 0x10230F,    //51,
    24, 0x103113,    //55,
    25, 0x103214,    //56,
    26, 0x103315,    //57,

 6, /* 6-bit codes */
    28, 0x10140A,    //46,
    55, 0x10421A,    //62,
    56, 0x10431B,    //63,
    57, 0x10441C,    //64,
    29, 0x102410,    //52,
    39, 0x103416,    //58,
 7,/* 7-bit codes */
    2,   0x100303,    //39,
    77,  0x103012,    //54,
    109, 0x104119,    //61,
    116, 0x10451D,    //65,
    108, 0x103517,    //59,
    118, 0x105422,    //70,
    119, 0x105523,    //71,
 6, /* 8-bit codes */
    3,   0x100404,    //40,
    7,   0x10150B,    //47,
    152, 0x102511,    //53,
    153, 0x10511F,    //67,
    234, 0x105220,    //68,
    235, 0x105321,    //69,
 2,/* 9-bit codes */
    12, 0x100505,    //41,
    13, 0x104018,    //60,
 6, /* 10-bit codes */
    11, 0x10501E,    //66,
    10, 0x016024,    //35,    //INTRA
    9,  0x005422,    //33,
    4,  0x003416,    //21,
    6,  0x00421A,    //25,
    8,  0x00441C,    //27,
 6, /* 11-bit codes */
    1,  0x000202,    //1,
    3,  0x00140A,    //9,
    10, 0x003517,    //22,
    11, 0x004119,    //24,
    14, 0x00431B,    //26,
    15, 0x005220,    //31,
 10, /* 12-bit codes */
    1,  0x001107,    //6,
    4,  0x001309,    //8,
    5,  0x00150B,    //10,
    8,  0x00200C,    //11,
    9,  0x00220E,    //13,
    10, 0x00230F,    //14,
    11, 0x002410,    //15,
    12, 0x002511,    //16,
    14, 0x003214,    //19,
    15, 0x004018,    //23,
 0, /* 13-bit codes */
 1, /* 14-bit codes */
    55, 0x005523,    //34,
 14, /* 15-bit codes */
    0,   0x000101,    //0,
    1,   0x000303,    //2,
    2,   0x000404,    //3,
    3,   0x000505,    //4,
    4,   0x001006,    //5,
    5,   0x001208,    //7,
    109, 0x005321,    //32,
    106, 0x00451D,    //28,
    107, 0x00501E,    //29,
    108, 0x00511F,    //30,
    6,   0x00210D,    //12,
    7,   0x003012,    //17,
    104, 0x003113,    //18,
    105, 0x003315,    //20,

-1 /* end of table */
};

//Table 74: k_x and k_y specified by MVRANGE
const extern VC1MVRange VC1_MVRangeTbl[4] =
{
    {9,     8,      256,    128},
    {10,    9,      512,    256},
    {12,    10,     2048,   512},
    {13,    11,     4096,   1024}
};

#endif //UMC_ENABLE_VC1_VIDEO_DECODER
